package com.nbjtjc.safe.service.edu;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduDailyExamineScoreMapper;
import com.nbjtjc.safe.model.edu.EduDailyExamineScore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EduDailyExamineScoreService {
	@Autowired
	  private EduDailyExamineScoreMapper eduDailyExamineScoreMapper;
		
	  public Result add(EduDailyExamineScore eduDailyExamineScore){
		        Result result=new Result();
		        if(ObjectUtil.isNull(eduDailyExamineScore)
//		        		||ObjectUtil.isNull(eduDailyExamineScore.getId())
//		        		||ObjectUtil.isNull(eduDailyExamineScore.getReqInvestId())
		        		||ObjectUtil.isNull(eduDailyExamineScore.getUserId())
		        		||ObjectUtil.isNull(eduDailyExamineScore.getExamineId())
		        		){		            
		        	result.setFalse("关键字段用户ID和考核表ID不能为空");
		            return result;
		        }
//主键为空或库中无此主键则为新建，插入数据
		        if(ObjectUtil.isNull(eduDailyExamineScore.getId())|| ObjectUtil.isNull(eduDailyExamineScoreMapper.selectByPrimaryKey(eduDailyExamineScore.getId()))){
		        	int res=eduDailyExamineScoreMapper.insertSelective(eduDailyExamineScore);
			        if(res==0){
			            result.setFalse("插入日常培训考核分数失败");
			            return result;
			        }
		        }else
		        {
		        	int res=eduDailyExamineScoreMapper.updateByPrimaryKeySelective(eduDailyExamineScore);
		        	 if(res==0){
		        		 result.setFalse("更新日常培训考核分数失败");
				         return result;

		        	 }
		        }
		        result.setData(eduDailyExamineScore);

		        return result;
		    }


	  
	  public Result delete(int eduDailyExamineScoreId){
	      Result result=new Result();
	      if(ObjectUtil.isNull(eduDailyExamineScoreId)){
	          result.setFalse("删除对象不能为空");
	          return result;
	      }
	      int res = eduDailyExamineScoreMapper.deleteByPrimaryKey(eduDailyExamineScoreId);
	      if(res==0){
	    	  result.setFalse("删除失败");
		      return result;
	
	      }
	      return result;
	  }
	  
	  public Result delete(EduDailyExamineScore eduDailyExamineScore){
	      Result result=new Result();
	      if(ObjectUtil.isNull(eduDailyExamineScore.getId())){
	          result.setFalse("删除对象不能为空");
	          return result;
	      }
	      eduDailyExamineScore.setCancel(1);
	      int res = eduDailyExamineScoreMapper.updateByPrimaryKey(eduDailyExamineScore);
	      if(res==0){
	    	  result.setFalse("删除失败");
		      return result;
	
	      }
	      return result;
	  }
	  
	  public Result find(EduDailyExamineScore eduDailyExamineScore) {
	      Result result = new Result();
	      PageHelper.startPage(eduDailyExamineScore.getPageCurrent(), eduDailyExamineScore.getPageSize());
	      List<EduDailyExamineScore> eduDailyExamineScores = eduDailyExamineScoreMapper.search(eduDailyExamineScore);
	      result.setData(new PageInfo<>(eduDailyExamineScores));

	      return result;
	  }
	  
	  public Result findDetail(EduDailyExamineScore eduDailyExamineScore) {
	      Result result = new Result();
	      PageHelper.startPage(eduDailyExamineScore.getPageCurrent(), eduDailyExamineScore.getPageSize());
	      List<EduDailyExamineScore> eduDailyExamineScores = eduDailyExamineScoreMapper.searchDetail(eduDailyExamineScore);
	      result.setData(new PageInfo<>(eduDailyExamineScores));

	      return result;
	  }
	  
	  
}
